home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / jpegagasrc / jpegaga / aslfiles.c < prev    next >
C/C++ Source or Header  |  1995-11-08  |  3KB  |  124 lines

  1. /* Display an ASL file requester */
  2.  
  3. #include <libraries/asl.h>
  4. #include <workbench/startup.h>
  5.  
  6. #define __NOLIBBASE__
  7. #include <proto/exec.h>
  8. #include <proto/asl.h>
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. #define MAXFILES 500
  14.  
  15. extern char *PicArray[];
  16. extern int NumPictures;
  17. extern short ASLPicSelect;
  18. extern void CloseDisplay(void);
  19. extern struct ScreenModeRequester *smr;
  20.  
  21. void ExitASL(void);
  22.  
  23. static struct FileRequester *fr = NULL;
  24.  
  25. struct TagItem frtags[] =
  26. {
  27.  { ASLFR_InitialPattern,"#?.(jpg|jpeg)"  },
  28.  { ASLFR_DoMultiSelect, (ULONG)TRUE },
  29.  { ASLFR_DoPatterns,    (ULONG)TRUE },
  30.  { ASLFR_RejectIcons,   (ULONG)TRUE },
  31.  { TAG_DONE,            (ULONG)TRUE }
  32. };
  33.  
  34.  
  35. extern struct Library *AslBase;
  36.  
  37. void ChooseFiles(void)
  38. {
  39.   struct WBArg *frargs;
  40.   int x,i;
  41.  
  42.   ASLPicSelect=0;
  43.  
  44.   if(!AslBase) AslBase=OpenLibrary("asl.library", 39L);
  45.  
  46.   if(AslBase)
  47.   {
  48.     if(!fr) fr = (struct FileRequester *)AllocAslRequest(ASL_FileRequest, frtags);
  49.  
  50.     if(fr)
  51.     {
  52.       if( AslRequest(fr, NULL) )
  53.       {       
  54.  
  55.         /* multiselect */
  56.         if(fr->rf_NumArgs)
  57.         {
  58.           frargs=fr->rf_ArgList;
  59.           for(x=0; x < fr->rf_NumArgs; x++)
  60.           {
  61.             PicArray[NumPictures] = malloc(strlen(fr->rf_Dir)+strlen(frargs[x].wa_Name)+3);
  62.             if(!PicArray[NumPictures]) ExitASL();
  63.             
  64.             strcpy(PicArray[NumPictures], fr->rf_Dir);
  65.             i = strlen(fr->rf_Dir);
  66.             if(i)
  67.             {
  68.               i--;
  69.               if(fr->rf_Dir[i] != ':' && fr->rf_Dir[i] != '/')
  70.                 strcat(PicArray[NumPictures], "/");
  71.             }
  72.             strcat(PicArray[NumPictures], frargs[x].wa_Name);
  73.             /* puts(PicArray[NumPictures]); */
  74.             NumPictures++;
  75.             if(NumPictures == MAXFILES)
  76.             {
  77.               printf("Too many files!\n");
  78.               break;
  79.             }
  80.             ASLPicSelect=1;
  81.           }
  82.         }
  83.         else
  84.         {
  85.           /* only one file selected */
  86.           PicArray[NumPictures] = malloc(strlen(fr->rf_Dir)+strlen(fr->rf_File)+3);
  87.           if(!PicArray[NumPictures]) ExitASL();
  88.    
  89.           strcpy(PicArray[NumPictures], fr->rf_Dir);
  90.           i = strlen(fr->rf_Dir);
  91.           if(i)
  92.           {
  93.             i--;
  94.             if(fr->rf_Dir[i] != ':' && fr->rf_Dir[i] != '/')
  95.               strcat(PicArray[NumPictures], "/");
  96.           }
  97.           strcat(PicArray[NumPictures], fr->rf_File);
  98.           NumPictures++;
  99.           ASLPicSelect=1;
  100.         }
  101.       }  
  102.     }
  103.   }
  104. }
  105.  
  106. void FreeASL(void)
  107. {
  108.   if(fr) FreeAslRequest(fr);
  109.   fr = NULL;
  110.   if(smr) FreeAslRequest(smr);
  111.   smr = NULL;
  112.   if(AslBase) CloseLibrary(AslBase);
  113.   AslBase = NULL;
  114. }
  115.  
  116.  
  117. void ExitASL(void)
  118. {
  119.  printf("Out of memory!\n");
  120.  FreeASL();
  121.  CloseDisplay();
  122.  exit(10);
  123. }
  124.